import api.ByeService;
import api.HelloObject;
import api.HelloService;
import rpc.serializer.CommonSerializer;
import rpc.transport.RpcClient;
import rpc.transport.RpcClientProxy;
import rpc.transport.netty.client.NettyClient;
import rpc.serializer.ProtobufSerializer;

/**
 * 测试用Netty消费者
 *
 * @Author wupeijie
 * @Date 2020/11/20 20:41
 */
public class NettyTestClient {
    public static void main(String[] args) {
        //初始客户端的NIO模型
        RpcClient client = new NettyClient(CommonSerializer.PROTOBUF_SERIALIZER);
        client.setSerializer(new ProtobufSerializer());
        //通过动态代理，声明要调用的方法后，通过JDK动态代理，调用NettyClient的sendRequst方法
        RpcClientProxy rpcClientProxy = new RpcClientProxy(client);
        HelloService helloService = rpcClientProxy.getProxy(HelloService.class);  //声明要调用的接口
        HelloObject object = new HelloObject(12, "This is a message");
        String res = helloService.hello(object);
        System.out.println(res);
        //通过动态代理,
        ByeService byeService = rpcClientProxy.getProxy(ByeService.class);
        System.out.println(byeService.bye("Netty"));
    }
}
